package com.muchfish.reactor.api;

import reactor.core.publisher.Flux;

public class ReactorFluxHandleExample {
    public static void main(String[] args) {
        Flux<Integer> source = Flux.just(1, 2, 0, 4, 5);

        // 处理元素和错误
        Flux<Integer> handledFlux = source.handle((value, sink) -> {
            if (value != 0) {
                sink.next(value); // 处理元素
            } else {
                sink.error(new RuntimeException("Cannot divide by zero")); // 处理错误
            }
        });

        handledFlux.subscribe(
                System.out::println,
                error -> System.err.println("Error: " + error.getMessage())
        );
    }
}
